<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>

    <script src="assets/js/jquery-3.2.1.min.js" type="text/javascript"></script>
    <script src="assets/js/xcConfirm.js"></script>
    <script src="assets/js/base.js"></script>
    <script src="assets/js/js.js" type="text/javascript"></script>
    <script src="assets/js/code/code_amazon.js"></script>
    <script src="assets/js/ajax.helper.js" type="text/javascript"></script>
    <script src="assets/js/popwin.js" type="text/javascript"></script>

    <LINK href="assets/css/css.css" type=text/css rel=stylesheet>

    <style>
        input [type="checkbox"]::before{ position:relative; top:3px; border:1px solid red}
    </style>
</head>
<body style="background:#FFF">
<div style="width:370px; margin:10px 0 10px 10px; height:auto; border-bottom:1px solid #ececec">
    <div id="topt" style="line-height:20px; font-weight:bold">已选 <button class="btn0" onClick="send()" style="float:right; position:relative; top:10px; margin-right:20px">确定</button></div>
    <div id="topv" style=" padding-left:10px; line-height:22px"></div>
</div>
<div id="mv" style=" padding-left:20px; line-height:22px"></div>
<script>
    var aid,sid;
    var catIdArr=new Array();
    function GetQueryString(name)
    {
        var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if(r!=null)return  unescape(r[2]); return null;
    }

    function drawTop()
    {
        var s="";
        for(var i=0;i<codeAmazonArr.length;i++)
        {
            if(codeAmazonArr[i][2]==sid)
            {
                if(jQuery.inArray(codeAmazonArr[i][0].toString(),catIdArr)>-1)
                {
                    s+="<div class='topv'><input type='checkbox' value='"+codeAmazonArr[i][0]+"' data-name='"+codeAmazonArr[i][1]+"' name='chkGroup' checked>"+codeAmazonArr[i][1]+"</div>";
                }
            }
        }
        $("#topv").html(s);
    }
    function drawMv()
    {
        var s="";
        var curCat=aid.split(",");
        for(var i=0;i<codeAmazonArr.length;i++)
        {
            if(codeAmazonArr[i][2]==sid)
            {
                var inf=jQuery.inArray( codeAmazonArr[i][0],curCat);
                s+="<div><input type='checkbox' value='"+codeAmazonArr[i][0]+"' name='chk' onChange='exChk(this)'>"+codeAmazonArr[i][1]+"</div>";
            }
        }
        $("#mv").html(s);
    }
    function exChk(o)
    {
        var v=o.value;
        if(o.checked)
        {
            if(jQuery.inArray(v,catIdArr))
            {
                catIdArr.push(v);
            }
        }
        else
        {
            var index = $.inArry(v,catIdArr);
            catIdArr.splice(index,1);
        }
        drawTop();
    }
    function send()
    {
        var arr=document.getElementsByName("chkGroup");
        var chkArr=new Array();
        for(var i=0;i<arr.length;i++)
        {
            if(arr[i].checked)
            {
                chkArr.push([arr[i].value,arr[i].getAttribute("data-name")]);
            }
        }
        if(chkArr.length>2)
        {
            showWarning(0,"最多选2个分类",200,60);
            setTimeout("$('.tips').fadeOut(0);",1500)
            return;
        }
        if(chkArr.length==0)
        {
            showWarning(0,"请勾选分类",200,60);
            setTimeout("$('.tips').fadeOut(0);",1500)
            return;
        }
        parent.getNewCategory(chkArr);
        parent.document.getElementById("popWinClose").click();
    }
    window.onload=function()
    {
        aid=GetQueryString("aid");
        sid=parseInt(GetQueryString("sid"));
        catIdArr=aid.split(",");
        drawTop();
        drawMv();
    }

</script>
</body>
</html>
